package com.aya.service.impl;


import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.dubbo.rpc.protocol.rest.support.ContentType;
import com.aya.AyaCommonException;
import com.aya.AyaServiceException;
import com.aya.facade.exp.CustomException;
import com.aya.facade.DictService;
import com.aya.facade.JsonVo;
import com.aya.facade.XmlVo;
import org.springframework.stereotype.Component;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("api")
@Service(interfaceClass = DictService.class)
@Component
public class DictServiceImpl implements DictService {

    @Override
    @GET
    @Path("testAll")
    @Produces({ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
    public XmlVo test() {
        System.out.println("test success");
        XmlVo dictVo = new XmlVo();
        dictVo.setName("zhangsan");
        return dictVo;
    }

    @GET
    @Path("testJson")
    @Produces({ContentType.APPLICATION_JSON_UTF_8})
    @Override
    public JsonVo testJson() {
        return new JsonVo();
    }

    @GET
    @Path("testXml")
    @Produces({ContentType.TEXT_XML_UTF_8})
    @Override
    public XmlVo testXml() {
        return new XmlVo();
    }


    @Override
    @GET
    @Path("test/exp/custom")
    @Produces({MediaType.APPLICATION_JSON})
    public JsonVo testExp() {
        throw new CustomException("test exp");
//        return new JsonVo();
    }

    @Override
    @GET
    @Path("test/exp/java")
    @Produces({MediaType.APPLICATION_JSON})
    public JsonVo testJava() {
        throw new IllegalArgumentException("param error");
//        return new JsonVo();
    }

    @Override
    @GET
    @Path("test/exp/common")
    @Produces({MediaType.APPLICATION_JSON})
    public JsonVo testCommon() {
        throw new AyaCommonException("test common");
//        return new JsonVo();
    }

    @Override
    @GET
    @Path("test/exp/service")
    @Produces({MediaType.APPLICATION_JSON})
    public JsonVo testservice() {
        throw new AyaServiceException("test service");
//        return new JsonVo();
    }
}
